package com.qike.duola.controller;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.qike.duola.domain.DuolaMessage;
import com.qike.duola.dto.*;
import com.qike.duola.response.BaseResult;
import com.qike.duola.response.RetResponse;
import com.qike.duola.service.DuolaCarService;
import com.qike.duola.service.DuolaMessageService;
import com.qike.duola.service.IsysResourceService;
import com.qike.duola.service.IsysUserService;
import com.qike.duola.utils.TokenUtil;
import com.qike.duola.vo.CarInfoVo;
import com.qike.duola.vo.CarListVo;
import com.qike.duola.vo.MessageListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(description = "消息控制器")
@CrossOrigin
public class MessageController {

    private static Logger logger = LoggerFactory.getLogger(MessageController.class);

    @Autowired
    private TokenUtil tokenUtil;

    @Autowired
    private DefaultKaptcha captchaProducer;
    @Autowired
    private DuolaMessageService duolaMessageService;
    @Autowired
    private IsysUserService userService;
    @Autowired
    private IsysResourceService isysResourceService;

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;


    /**
     * 添加消息
     *
     * @return
     */
    @PostMapping("/msgAdd")
    @ApiOperation("添加消息")
    @ResponseBody
    public BaseResult msgAdd(@RequestBody MsgAddDto msgAddDto) {
        try {
            duolaMessageService.msgAdd(msgAddDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            logger.error(e.getMessage());
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 消息列表
     *
     * @return
     */
    @GetMapping("/messageList")
    @ApiOperation("消息列表")
    @ResponseBody
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = MessageListVo.class)
    })
    public BaseResult messageList(MessageListDto messageListDto) {
        try {
            MessageListVo vo = duolaMessageService.messageList(messageListDto);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            logger.error(e.getMessage());
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 读取消息
     *
     * @return
     */
    @GetMapping("/readMsg")
    @ApiOperation("读取消息 不传ids 就读取所有小")
    @ResponseBody
    public BaseResult readMsg(List<Integer> ids) {
        try {
            duolaMessageService.readMsg(ids);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            logger.error(e.getMessage());
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


}
